<?php
/**
 * Created by PhpStorm.
 * User: 86158
 * Date: 2021/6/15
 * Time: 23:06
 */

namespace App\Models\access;


use App\Models\Model;
use App\Models\User;

class AccessVoteLeader extends Model
{
    protected $fillable = [
        'access_id',
        'leader_id',
        'rate',
        'status',
        'leader_type',
        'updated_at'
    ];

//    public function accessVote()
//    {
//        return $this->belongsTo(AccessVote::class,'id','access_id');
//    }

    public function access()
    {
        return $this->hasOne(AccessVote::class,'id','access_id');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','leader_id');
    }

    public function lists($user_id,$keyword='')
    {
        return self::where('leader_id',$user_id)->with('access')->get()->toArray();
    }

    public function detail($user_id,$access_id)
    {
        $map = [
            'access_id' => $access_id,
            'leader_id'   => $user_id
        ];
        $data = self::where($map)->with('access')->with('user')->get()->toArray();
        return $data;
    }
}